package com.tcm.doctor.web.controller;

import com.base.core.exception.ServiceException;
import com.base.core.utils.R;
import com.tcm.doctor.domain.dto.DoctorVerifyDTO;
import com.tcm.doctor.service.DoctorVerifyService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/doctor")
@RestController
public class DoctorVerifyController {

    @DubboReference(version = "0.0.1-alpha",timeout = 6000, check = false, retries = 3)
    private DoctorVerifyService doctorVerifyService;

    @GetMapping("/verify/view")
    public R view(@RequestParam("userId") Long userId) {
       return R.success(doctorVerifyService.findByUserId(userId));
    }

    @PostMapping("/verify/save")
    public R create(@RequestBody DoctorVerifyDTO doctorVerifyDto) {
        try{
            doctorVerifyService.save(doctorVerifyDto);
        }catch (ServiceException e){
            return R.fail(e.getResult().getCode(), e.getMessage());
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.success();
    }

    @GetMapping("/verify/delete")
    public R delete(@RequestParam("userId") Long userId) throws Exception{
        try{
            doctorVerifyService.deleteLogic(userId);
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.success();
    }
}

